# import pandas as pd
# import numpy as np

# print(pd.__version__)

# a = pd.Series([1,3,5,6,8])
# print(a) # 结果中第一列为索引，从0开始。第二列为实际的数据

# # 由词典生成的Series对象
# b = pd.Series({1:'a',3:'b',5:'c',6:'d',8:'e'})
# print(b)

# c = list("abcde")
# d = [1,3,4,6,8]
# e = pd.Series(data=c,index=d) # 分别指定数据和索引，生成Series对象
# print(e)

# g = pd.Series(1,np.arange(5)) # Series对象含有5个值均为1的元素
# print(g)

# f = pd.Series(np.random.rand(5),index=np.arange(10,15),name='test_S') # f是由numpy 随机数据生成的Series对象
# print(f)

# print(f[12])

# data = [['zhangsan',1992],['lisi',1991],['wangwu',1990]]
# df = pd.DataFrame(data,columns=['Name','Year'])
# print(df)

# data = {'User':['zhangsan','lisi','wangwu'],'Year':[1992,1991,1990],'Score':[90,80,70]}
# df = pd.DataFrame(data,index=list('ABC')) # 指定行索引
# print(df)

# df = pd.DataFrame(np.random.rand(6).reshape(2,3))
# print(df)

# dates = pd.date_range("20250101",periods=6) # 得到6个日期索引
# print(dates)

# df = pd.DataFrame(np.random.randn(6,4),index=dates,columns=list('ABCD'))
# print(df)

# df = pd.DataFrame({'A': 1.,'C': pd.Series(1,index=list(range(4)),dtype='float32'),'D':np.array([3] * 4,dtype='int32'),'E': pd.Categorical(["test","train","test","train"]),'F':'foo'})
# print(df)

# print(df.index)

# print(df.columns)

# print(df.dtypes)

# print(df.T)

# dates = pd.date_range("20250701",periods=6)
# # print(dates)

# df = pd.DataFrame(np.arange(24).reshape(6,4),dates,columns=list('ABCD'))
# print(df) #6行4列，行索引从20250701到20250706，列索引从A到D

# print(df['A'])

# print(df.loc['2025-07-02'])

# print(df.iloc[1])

# print(type(df.loc['2025-07-02']))

# print(type(df.iloc[1]))

# print(df[0:3]) # 取前3行数据，也可以写成df[:3]

# print(df['2025-07-01':'2025-07-03']) # 取两个索引之间的各行数据，注意含最后一个索引行

# print(df[df.B > 10]) # 筛选出B列数据大于10的行数据

# print(df[df.B.isin([0,1,2,3,4,5])]) #筛选出B列中值在给定列表中的元素所在的行

# print(df[df%2 == 0]) # 对所有元素筛选，保留所有为偶数的元素，不满足条件的元素置为Nan

# print(df.loc[:,["A","B"]])

# print(df.loc["20250701":"20250704",["A","B"]])

# print(df.loc["20250702",["A","B"]]) # 注意返回的是Series对象

# print(df.loc["20250702","A"]) # 注意返回的是元素值
# print(df.at["20250702","A"])

# print(df.iat[1,1])

# df = pd.DataFrame(np.arange(24).reshape(6,4))
# print(df)

# dates = pd.date_range("20250701",periods=6)
# df.index = dates #修改行索引
# print(df)

# df.columns = list('ABCD') #修改列索引，变为从A到D
# print(df)

# 6行5列，行索引未变，增加一列，对应列索引为E
# df1 = df.reindex(index=df.index,columns=list(df.columns)+['E']) 
# print(df1)
# df1.iloc[3,4] = 1 # 填充此行的空数据
# print(df1)

# df2 = df1.dropna(axis=0,how="any") # 删除含有缺失数据的行，返回新的对象，原对象未改变。axis 默认为0，表示删除行，因此axis=0可省略，等价于df1.dropna(how="any")
# print(df2)

# df3 = df1.dropna(axis=1,how="any")
# print(df3)

# df4 = df1.fillna(value=5) #将所有缺失数据填充为5，返回新的对象，原对象未改变
# print(df4)

# dates = pd.date_range("20250701",periods=6)

# df = pd.DataFrame(np.arange(24).reshape(6,4),dates,columns=list('ABCD'))
# print(df) #6行4列，行索引从20250701到20250706，列索引从A到D

# df2 = pd.DataFrame(np.random.randn(6,4))
# print(df2) # 初始面板数据

# # df3 = pd.concat([df,df2]) # 合并，变为12行8列
# # print(df3)

# df2.columns = df.columns #变更 df3 的列索引
# # df5 = pd.concat([df,df2])  #再次纵向合并，相同列索引的数据合并为一列，变为 12 行 4 列
# # print(df5)

# df.index = range(len(df.index)) # 修改df的行索引为从0到5
# df6 = pd.concat([df,df2],axis=1) #横向合并，变为6行8列，注意列索引名称
# print(df6)
# import pandas as pd
# import numpy as np
# import tables
# list1 = ["foo","bar","foo","bar","foo","bar"]
# list2 = ["one","one","two","three","two","two"]
# list3 = np.random.randint(6,size=(6))
# list4 = np.random.randint(6,size=(6))
# df = pd.DataFrame({"A": list1,"B": list2,"C": list3,"D": list4})
# print(df)

# print(df.groupby('A').sum()) # 求和

# r = df.groupby(['A','B']).mean()
# print(r)

# print(r.loc[('bar','three')])

# import pandas as pd
# import numpy as np
# import tables
# from openpyxl.workbook import Workbook
# list1 = ["foo","bar","foo","bar","foo","bar"]
# list2 = ["one","one","two","three","two","two"]
# list3 = np.random.randint(6,size=(6))
# list4 = np.random.randint(6,size=(6))
# df = pd.DataFrame({"A": list1,"B": list2,"C": list3,"D": list4})
# # df.to_csv("test.csv") # 写入cvs文件
# # df.to_hdf("test.h5",key="df") # 写入hdf5文件，key指定存入的group名称
# # df.to_excel("test.xlsx",sheet_name="Sheet1") # 写入excel文件，sheet_name指定sheet名称
# df1 = df.copy()
# with pd.ExcelWriter('output.xlsx') as writer:
#       df.to_excel(writer, sheet_name='Sheet_name_1')
#       df1.to_excel(writer, sheet_name='Sheet_name_2')
# with pd.ExcelWriter('output.xlsx',mode='a',engine='openpyxl') as writer:
#       df.to_excel(writer, sheet_name='Sheet_name_3')

import pandas as pd
import numpy as np
import tables
from openpyxl.workbook import Workbook

df1 = pd.read_csv("test.csv") #读取csv文件，参数为文件名
print(df1)

df2 = pd.read_hdf("test.h5","df") # 从hdf5文件读取
print(df2)

df3 = pd.read_excel("test.xlsx","Sheet1",index_col=0,na_values=["NA"])
print(df3)